#ifndef PLANNER_H
#define PLANNER_H

#include "timer.hpp"
#include "Prm.h"

#include <QPointF>
#include <QVector>
#include <QPolygonF>
#include "basic_typedef.h"
#include "Scene.h"
#include "Graph.h"
#include <CGAL/Random.h>
#include <boost/shared_ptr.hpp>
#include "Sampler.h"
#include "CollisionDetector.h"
#include "Clearance_detector.hpp"


#define MAX_TIME_SECS 60

class Planner
{
public:
	
	////////////////////////
	// C'tors & D'tors
	////////////////////////

	Planner(Scene* scene, int time=MAX_TIME_SECS, boolean measure=false, double alpha=1, vector<vector<Conf>>* path=NULL, double* quality=NULL);

	~Planner(void);

	////////////////////////
	// modifiers
	////////////////////////

	void run();

	////////////////////////
	// helpers
	////////////////////////

private:
	Point_2		transformToCGAL(QPointF qp);

	Prm get_prm_with_solution(UINT32& number_of_vertices_to_try,CollisionDetector* collision_detector,MultiRobotsSampler* multi_robots_sampler);

	Prm get_combined_solution(UINT32 number_of_solutions,UINT32 number_of_vertices_to_start_from,CollisionDetector* collision_detector,MultiRobotsSampler* multi_robots_sampler);

	Prm merge_two_solutions(Prm& prm1,Prm& prm2);

	QPointF		transformToQT(Conf cp);

	QVector<QPointF> transformToQT(ConfSet cs);

	QVector<QVector<QPointF> > transformToQT(list<vector<Conf> > path);

	void		transform_path_for_gui();

	void	extract_scenario_from_gui();

	///////////////////////
	// Data members
	///////////////////////

	Scene*				m_scene;
	vector<Polygon_2>	m_robot_polygons;
	Obstacles			m_obstacles;	// polygonal obstacles + scenario boundaries
	ConfSet				m_start_confs, m_target_confs;
	Room				m_room;
	int					m_robot_num;
	vector<ConfSet>		m_path;			// path section - robot - configuration
	Timer				_timer;
	bool				_use_clearance;
	double				_alpha;
	vector<vector<Conf>>* _path_return;
	double*				_quality_return;
	Clearance_detector_ie* r1_clearance_detector;
	Clearance_detector_ie* r2_clearance_detector;

	static const UINT32 INITIAL_NUMBER_OF_VERTICES;
};


#endif